<template>
	<view class="pageV">
		<u-navbar title="切换合伙人" placeholder :autoBack="true" leftIconColor="#fff" bgColor="#FFFFFF"
			:titleStyle="titleStyle">

		</u-navbar>
		
		<view v-if="mRoleList.length>0" class="centV">
			<view @click="onItemClick(item,index)" :class="pos==index?'itemVTo':'itemV'"
				v-for="(item,index) in mRoleList" :key="index">
				<view class="itemLeftV">
					<view class="titleTv">{{item.shop_name}}</view>
					<view class="moneyV">
						<view class="moneyTv1">{{item.role_name}}</view>
						<view class="moneyTv2">{{item.money}}</view>
					</view>
				</view>
				<image class="itemRightV" :src="pos==index?'../../static/select_.svg':'../../static/select.svg'">
				</image>
			</view>
		</view>
		<view v-if="mRoleList.length>0" class="bottomV">
			<view class="confirmV" @click="onConfirmClick()">确认</view>
		</view>
		
		<view  v-if="mRoleList.length==0" class="noV">
			<image src="https://s1.ax1x.com/2023/04/19/p9FHmWR.png" mode="aspectFill"></image>
			<view>咦~，一片空白，还没有数据呢</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				titleStyle: {
					"color": "#ffffff"
				},
				mRoleList: [],
				pos: -1,
				type:0,//是否是第一次进来  0第一次  1第二次
			}
		},
		onLoad(e) {
			console.log("----",e.type);
			this.type = e.type;
			this.getRoleList();
		},
		methods: {
			getRoleList() {
				this.$api.getRoleList({}).then((res) => {
					this.mRoleList = res;
				}).catch((e) => {
					uni.$u.toast(e.msg === undefined ? "请求失败" : e.msg)
				})
			},
			onItemClick(item, index) {
				this.pos = index;
			},
			onConfirmClick() {
				if (this.pos == -1) {
					uni.$u.toast("请选择")
				}
				if(this.type==0){
					// this.$u.route({
					// 	type:'redirectTo',
					// 	url: '/pages/me/Copartner',
					// 	params: {
					// 		id: this.mRoleList[this.pos].role_id,
					// 	}
					// })
					this.$u.route({
						type:'redirectTo',
						url: '/shop/New/NewSHome',
						params: {
							id: this.mRoleList[this.pos].role_id,
							shop_id:this.mRoleList[this.pos].shop_id
						}
					})
				}else{
					let pages = getCurrentPages()
					let prevPage = pages[pages.length - 2] //上一页页面实例
					uni.navigateBack({
						delta: 1,
						success: () => {
							prevPage.$vm.otherFun(this.mRoleList[this.pos].role_id) // 给上一页绑定方法otherFun,传参地址id
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.pageV {
		display: flex;
		flex-direction: column;
		min-height: 100vh;
	}

	.centV {
		flex: 1;
		padding-left: 30rpx;
		padding-right: 30rpx;
	}

	.bottomV {
		height: 160rpx;
		padding-left: 30rpx;
		padding-right: 30rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.confirmV {
		width: 100%;
		height: 100rpx;
		background: #E6A5B4;
		border-radius: 10rpx;
		color: #FFFFFF;
		font-size: 32rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.itemV {
		display: flex;
		align-items: center;
		height: 150rpx;
		padding-left: 30rpx;
		padding-right: 30rpx;
		background-image: url("https://s1.ax1x.com/2023/04/19/p9Fmc2n.png");
		background-size: 100% 100%;
		margin-bottom: 30rpx;
		border: 2rpx solid #00000000;
	}

	.itemVTo {
		display: flex;
		align-items: center;
		height: 150rpx;
		padding-left: 30rpx;
		padding-right: 30rpx;
		background-image: url("https://s1.ax1x.com/2023/04/19/p9Fmc2n.png");
		background-size: 100% 100%;
		margin-bottom: 30rpx;
		border: 2rpx solid #E6A5B4;
	}

	.itemLeftV {
		flex: 1;
	}

	.itemRightV {
		width: 43rpx;
		height: 43rpx;
	}

	.titleTv {
		color: #E6A5B4;
		font-size: 32rpx;
	}

	.moneyV {
		display: flex;
		align-items: center;
		margin-top: 10rpx;
	}

	.moneyTv1 {
		font-size: 28rpx;
		color: #FFFFFF;
	}

	.moneyTv2 {
		font-size: 24rpx;
		color: #ABABAB;
		margin-left: 30rpx;
	}
	
	.noV {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		margin-top: 100rpx;
		image {
			width: 360rpx;
			height: 194rpx;
		}
	
		view {
			font-size: 28rpx;
			color: #999999;
			margin-top: 47rpx;
		}
	}
</style>
